var playlistVar = 1;
var page=1;
//歌单推荐

$(function () {
    $(".playlistClass").click(function () {
        playlistVar = $(this).attr("value");
        $.ajax({
            "url": "CSXServlet",
            "type": "GET",
            "data": {"opr":playlistVar,"page":page},
            "dataType": "JSON",
            "success": function (data) {
                /*alert(data);
                alert(playlist.playlistName);
                alert(playlist.playlistPoster);*/
                $.each(data,function (index,playlist) {
                    $('.playlist[playlist-index='+(index+1)+'] .text-ellipsis:first-child').html(playlist.playlistName).attr({"href":"http://localhost:8080/music/playlist?id="+playlist.playlistId,"target":"_blank"})
                        .next().html("播放量："+playlist.playlistPlaycount);
                    $('.playlist[playlist-index='+(index+1)+'] img').attr('src',playlist.playlistPoster);
                    $(".playlist[playlist-index="+(index+1)+"] .text-center a").attr({"class":"js-play","data-type":"playlist","data-id":playlist.playlistId});
                })
            }
        })
    })
    $(".playlistClass[value=1]").click();
});

//分页底端
$(document).ready(function () {
    $(".playlistPage").click(function () {
        var page = $(this).attr("value");
        $.ajax({
            "url": "CSXServlet",
            "type": "GET",
            "data": {"opr":playlistVar,"page":page},
            "dataType": "JSON",
            "success": function (data) {
                $.each(data,function (index,playlist) {
                    $('.playlist[playlist-index='+(index+1)+'] .text-ellipsis:first-child').html(playlist.playlistName).next().html("播放量："+playlist.playlistPlaycount);
                    $('.playlist[playlist-index='+(index+1)+'] img').attr('src',playlist.playlistPoster).css("height","282px");
                })
            }
        })
    })
})


//分页左侧边
$(document).ready(function () {
    $(".playlistLeft").click(function () {
        if(page==1){
            page=3;
        } else{
            page--;
        }
        //playlistVar = $(this).attr("value")
        $.ajax({
            "url": "CSXServlet",
            "type": "GET",
            "data": {"opr":playlistVar,"page":page},
            "dataType": "JSON",
            "success": function (data) {
                $.each(data,function (index,playlist) {
                    $('.playlist[playlist-index='+(index+1)+'] .text-ellipsis:first-child').html(playlist.playlistName).next().html("播放量："+playlist.playlistPlaycount);
                    $('.playlist[playlist-index='+(index+1)+'] img').attr('src',playlist.playlistPoster).css("height","282px");
                })
            }
        })
    })
})


//分页右侧边
$(document).ready(function () {
    $(".playlistRight").click(function () {
        if(page==3){
            page=1;
        } else{
            page++;
        }
        $.ajax({
            "url": "CSXServlet",
            "type": "GET",
            "data": {"opr":playlistVar,"page":page},
            "dataType": "JSON",
            "success": function (data) {
                $.each(data,function (index,playlist) {
                    $('.playlist[playlist-index='+(index+1)+'] .text-ellipsis:first-child').html(playlist.playlistName).next().html("播放量："+playlist.playlistPlaycount);
                    $('.playlist[playlist-index='+(index+1)+'] img').attr('src',playlist.playlistPoster).css("height","282px");
                })
            }
        })
    })
})


